var vm = new Vue({
    el: "#app",
    data: {
        arr: [
            { img: "./img/good1.jpg", name: "黄焖鸡米饭", price: 18, num: 1 },
            { img: "./img/good2.png", name: "农家猪脚饭", price: 22, num: 1 },
            { img: "./img/good3.png", name: "云南过桥米线", price: 14, num: 1 }
        ]

    },
    methods: {
        clear() {
            this.arr = []
        },
        jian(item) {
            if (item.num > 1) {
                item.num--
            }
        },
        add(item) {
            if (item.num < 5) {
                item.num++
            }
        }
    },
    computed: {
        allNum() {
            var allnum = 0;
            this.arr.forEach(item => { allnum += item.num / 1 }
            )
            return allnum;
        },
        allPrice() {
            var allprice = 0;
            this.arr.forEach(item => { allprice += item.num * item.price }
            )
            return allprice;
        }
    }
})